package com.api.syh56.shengyunhui.config;

import com.api.syh56.shengyunhui.handler.JWTHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class SpringMvcConfig implements WebMvcConfigurer {

    /**
     * 自定义拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new JWTHandler())
                //拦截全部
                .addPathPatterns("/**")
                //不需拦截的请求
                .excludePathPatterns(this.exclud());
    }
    /**
     *     不需拦截的请求
     */
    public String[] exclud(){
        String[] urls= {
                "/error",
                "/user/login",
                "/user/sendsms",
                "/common/getCity",
                "/common/**",
//                "/waybill/driver/recentWaybills",
                "/wechatpay/**",
                "/wechatpay/*",
                "/wechatpay/success",
                "/wechatpay/refund",
                "/admin/user/login",
                "/admin/agreement/selectBykeyword",
                "/admin/agreement/selectBykeywordhtml",
                "/test/**",
                "/test/*",
                "/test/test",
                "/test/fapiao",
                "/test/chaxun",
                "/slide/show",
//                "/zjxl/businessLicenseOCR",
                "/zjxl/visualRoute",
                "/zjxl/**",

        };
        return urls;
    }

    /**
     * 防止全表更新与删除拦截器
     * @return
     */
//    @Bean
//    public MybatisPlusInterceptor optimisticLockerInnerInterceptor() {
//        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
//        // 防止全表更新和删除的拦截器
//        interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
//        return interceptor;
//    }

}

